
<template>
  <div class="app-container">
    <div class="search-container">
      <el-form ref="queryFormRef" :model="queryParams" label-width="auto" :inline="true">
        <el-form-item label="车型" prop="vehicleTypeIds">
          <el-select filterable clearable @keyup.enter="handleQuery" v-model="queryParams.vehicleTypeIds" placeholder="请选择" style="width: 256px">
            <el-option v-for="item in carTypeArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="车品牌" prop="vehicleBrand">
          <el-input placeholder="请输入" @keyup.enter="handleQuery" v-model="queryParams.vehicleBrand"></el-input>
        </el-form-item>
        <el-form-item label="车系" prop="vehicleSeries">
          <el-input placeholder="请输入" @keyup.enter="handleQuery" v-model="queryParams.vehicleSeries"></el-input>
        </el-form-item>
        <el-form-item label="携程车型" prop="ctripId">
          <el-select filterable clearable @keyup.enter="handleQuery" v-model="queryParams.ctripId" placeholder="请选择" style="width: 256px">
            <el-option v-for="item in xcCarTypeArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="飞猪车型" prop="fliggyId">
          <el-select filterable clearable @keyup.enter="handleQuery" v-model="queryParams.fliggyId" placeholder="请选择" style="width: 256px">
            <el-option v-for="item in fzCarTypeArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="南航车型" prop="nanhangId">
          <el-select filterable clearable @keyup.enter="handleQuery" v-model="queryParams.nanhangId" placeholder="请选择" style="width: 256px">
            <el-option v-for="item in nhCarTypeArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="航旅车型" prop="hanglvId">
          <el-select filterable clearable @keyup.enter="handleQuery" v-model="queryParams.hanglvId" placeholder="请选择" style="width: 256px">
            <el-option v-for="item in hnCarTypeArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="同程车型" prop="tcId">
          <el-select filterable clearable @keyup.enter="handleQuery" v-model="queryParams.tcId" placeholder="请选择" style="width: 256px">
            <el-option v-for="item in TcCarTypeArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery">
            <template #icon><Search /></template>
            搜索
          </el-button>
          <el-button @click="handleResetQuery">
            <template #icon><Refresh /></template>
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <template #header>
        <el-button type="success" @click="handleEdit('新增', {})">
          <template #icon><Plus /></template>
          新增
        </el-button>
      </template>
      <el-table v-loading="loading" :data="TableData" highlight-current-row row-key="id" @row-click="handleRowClick">
        <el-table-column label="车型" min-width="120" align="center" prop="vehicleType"></el-table-column>
        <el-table-column label="车品牌" min-width="120" align="center" prop="vehicleBrand"></el-table-column>
        <el-table-column label="车系" min-width="120" align="center" prop="vehicleSeries"></el-table-column>
        <el-table-column label="携程车型" min-width="80" align="center" prop="ctripId">
          <template #default="scope">
            <div>{{ xcCarEnum[scope.row.ctripId] }}</div>
          </template>
        </el-table-column>
        <el-table-column label="飞猪车型" min-width="80" align="center" prop="fliggyId">
          <template #default="scope">
            <div>{{ fzCarTypeEnum[scope.row.fliggyId] }}</div>
          </template>
        </el-table-column>
        <el-table-column label="南航车型" min-width="80" align="center" prop="nanhangId">
          <template #default="scope">
            <div>{{ nhCarTypeEnum[scope.row.nanhangId] }}</div>
          </template>
        </el-table-column>
        <el-table-column label="航旅车型" min-width="80" align="center" prop="hanglvId">
          <template #default="scope">
            <div>{{ hvCarEnum[scope.row.hanglvId] }}</div>
          </template>
        </el-table-column>
        <el-table-column label="同程车型" min-width="80" align="center" prop="tcId">
          <template #default="scope">
            <div>{{ TcCarTypeEnum[scope.row.tcId] }}</div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" align="center" label="操作" width="220">
          <template #default="scope">
            <div style="display: flex; justify-content: center; align-items: center">
              <el-button type="primary" link size="small" @click.stop="handleEdit('编辑', scope.row)">
                <template #icon><Pointer /></template>
                编辑
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-if="total > 0" v-model:total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize" @pagination="handleQuery" />
    </el-card>
    <!-- 改派 -->
    <EditModal ref="editModalRef" @success="handleQuery" />
  </div>
</template>

<script setup lang="ts">
import { ref, reactive } from "vue";
import CommonApi from "@/api/common";
import EditModal from "./components/editModal.vue";
import {
  carTypeArr,
  xcCarTypeArr,
  fzCarTypeArr,
  nhCarTypeArr,
  hnCarTypeArr,
  TcCarTypeArr,
  TcCarTypeEnum,
  xcCarEnum,
  fzCarTypeEnum,
  nhCarTypeEnum,
  hvCarEnum,
} from "@/enums/common";
import { MenuTypeEnum } from "@/enums/MenuTypeEnum";
import JntApi from "@/api/jnt";

const queryFormRef = ref();
const total = ref(0);
const supplierOptions = ref();
const cityOptions = ref();
const useTimes = ref();
const createdTimes = ref();
const editModalRef: any = ref(null);

const loading = ref(false);

// 查询参数
const queryParams = reactive<MenuQuery>({
  pageNo: 1,
  pageSize: 10,
});
// 菜单表格数据
const TableData = ref([]);

// 选择表格的行菜单ID
const selectedMenuId = ref<number | undefined>();

//编辑触发
function handleEdit(title: string, row: any) {
  editModalRef.value.edit(title, row);
}
// 查询菜单
function handleQuery() {
  loading.value = true;
  JntApi.getVehicleList(queryParams)
    .then((data) => {
      TableData.value = data.result;
      total.value = data.total * 1;
    })
    .finally(() => {
      loading.value = false;
    });
}

function handleUseTimeChange(time: any) {
  if (time) {
    queryParams.useTimeFrom = `${time[0]} 00:00:00`;
    queryParams.useTimeTo = `${time[1]} 23:59:59`;
  } else {
    queryParams.useTimeFrom = undefined;
    queryParams.useTimeTo = undefined;
  }
}
function handleCreatedTimeChange(time: any) {
  if (time) {
    queryParams.createTimeFrom = `${time[0]} 00:00:00`;
    queryParams.createTimeTo = `${time[1]} 23:59:59`;
  } else {
    queryParams.createTimeFrom = undefined;
    queryParams.createTimeFrom = undefined;
  }
}

// 重置查询
function handleResetQuery() {
  queryParams.useTimeFrom = undefined;
  queryParams.useTimeTo = undefined;
  queryParams.createTimeFrom = undefined;
  queryParams.createTimeTo = undefined;
  useTimes.value = null;
  createdTimes.value = null;

  queryFormRef.value.resetFields();
  queryParams.pageNo = 1;
  handleQuery();
}

// 行点击事件
function handleRowClick(row: MenuVO) {
  // 记录表格选择的菜单ID，新增子菜单作为父菜单ID
  selectedMenuId.value = row.id;
}

onMounted(() => {
  handleQuery();
  CommonApi.getSupplier({ pageNo: 1, pageSize: 9999, status: 1 }).then((data) => {
    if (data.code == 0) {
      supplierOptions.value = data.result;
    }
  });
  CommonApi.getCity({ pageNo: 1, pageSize: 9999 }).then((data) => {
    if (data.code == 0) {
      cityOptions.value = data.result;
    }
  });
});
</script>
<style lang="scss" scoped>
.red_rate {
  color: red;
}
.address_box {
  display: flex;
  flex-direction: column;
  align-items: left;
  justify-content: left;
  .item {
    display: flex;
    align-items: center;
    margin: 4px 0;
    .tag {
      width: 50px;
      height: 23px;
      text-align: center;
      color: orange;
      background: #fff8e6;
    }
    .tag2 {
      color: #3fd175;
      background: #e7faf0;
    }
  }
}
</style>
